package com.ins1st.plus.util;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ins1st.plus.base.ControllerResult;

import javax.servlet.http.HttpServletRequest;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @program: ins1st-plus
 * @description: 分页工厂
 * @author: coderSun
 * @create: 2019-09-05 13:24
 **/
public class PageFactory {


    /**
     * @return
     */
    public static Page defaultPage() {
        HttpServletRequest request = RequestContextHolderUtil.getRequest();
        return new Page(Long.valueOf(request.getParameter("offset")), Long.valueOf(request.getParameter("limit")));
    }


    /**
     * 创建分页
     *
     * @param page
     * @return
     */
    public static Object createPage(IPage page) {
        ConcurrentHashMap map = new ConcurrentHashMap<>();
        map.put("rows", page.getRecords());
        map.put("total", page.getTotal());
        return map;
    }

}
